/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 东莞呵呵
 * Date:2022-09-10
 * Time:10:17
 */
class Counter4 {
    public static int sum = 0;

    public static void increase() {
        synchronized (Counter4.class) {
            sum++;
        }
    }
}

public class Demo9 {
    public static void main(String[] args) throws InterruptedException {

        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 50000; i++) {
                    Counter4.increase();
                }
            }
        });
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 50000; i++) {
                    Counter4.increase();
                    ;
                }
            }
        });

        t1.start();
        t2.start();

        t1.join();
        t2.join();

        System.out.println(Counter4.sum);
    }
}
